﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Wisdom.Core
{
    /// <summary>
    /// Defines a Registry class which holds the list of the task that would be executed in the application.
    /// </summary>
    public class BootstrapperTasksRegistry : TasksRegistry, IBootstrapperTasksRegistry
    {
        /// <summary>
        /// Includes the specified task.
        /// </summary>
        /// <typeparam name="TTask">The type of the task.</typeparam>
        /// <returns></returns>
        public IBootstrapperTasksRegistry Include<TTask>() where TTask : IBootstrapperTask
        {
            return Include<TTask>(null);
        }

        /// <summary>
        /// Includes the specified task and also allows to configure.
        /// </summary>
        /// <typeparam name="TTask">The type of the task.</typeparam>
        /// <param name="configure">The configure.</param>
        /// <returns></returns>
        public virtual IBootstrapperTasksRegistry Include<TTask>(Action<TTask> configure) where TTask : IBootstrapperTask
        {
            Action<object> modified = null;

            if (configure != null)
            {
                modified = t => configure((TTask)t);
            }

            Include(typeof(TTask), modified);

            return this;
        }

        /// <summary>
        /// Excludes this instance.
        /// </summary>
        /// <typeparam name="TTask">The type of the task.</typeparam>
        /// <returns></returns>
        public virtual IBootstrapperTasksRegistry Exclude<TTask>() where TTask : IBootstrapperTask
        {
            Type taskType = typeof(TTask);

            Exclude(taskType);

            return this;
        }
    }
}